<?php
/**
 * Description:
 *
 * @author      Eden
 * @datetime    2017/3/20 21:05
 * @copyright   WuHan HuQi Technology Co.,Ltd.
 * @url         http://cnhuqi.com
 */

require_once FCPATH . '/application/third_party/wechat/include.php';

use Wechat\Loader;

class Menu extends CI_Controller
{

    /**
     * 初始化
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 初始化菜单
     */
    public function index()
    {
        $options = $this->config->item('wechat');
        Loader::config($options);
        $wechat = Loader::get("menu");
        if ($wechat->getMenu()) {
            $wechat->deleteMenu();
        }

        $ret = $wechat->createMenu($this->_getMenu());
        if (!$ret) {
            echo 'ErrorCode:' . $wechat->errCode;
            echo '<br>';
            echo 'ErrorMsg:' . $wechat->errMsg;
        } else {
            echo 'Menu Init Success.';
        }
    }

    public function _getMenu()
    {
        return [
            'button' => [
                0 => [
                    'name' => '关于我们',
                    'sub_button' => [
                        0 => [
                            'type' => 'view',
                            'name' => '公司简介',
                            'url' => 'http://u4212428.viewer.maka.im/k/ZUCB1KTO'
                        ],
                        1 => [
                            'type' => 'view',
                            'name' => '基地直播',
                            'url' => 'http://square.ys7.com/play/index?cameraId=1361690'
                        ],
                        2 => [
                            'type' => 'view',
                            'name' => 'APP下载',
                            'url' => 'http://a.app.qq.com/o/simple.jsp?pkgname=com.tiger.socol.gu'
                        ],
                        3 => [
                            'type' => 'view',
                            'name' => '商家入驻',
                            'url' => 'http://v3.rabbitpre.com/mspa/BAA2VvEJo'
                        ]
                    ],
                ],
                1 => [
                    'name' => '进入商城',
                    'type' => 'view',
                    'url' => 'http://wx.api.qiuqiugu.com/index'
                ],
                2 => [
                    'name' => '会员中心',
                    'sub_button' => [
                        0 => [
                            'type' => 'view',
                            'name' => '个人中心',
                            'url' => 'http://wx.api.qiuqiugu.com/center',
                        ],
                        1 => [
                            'type' => 'click',
                            'name' => '客服中心',
                            'key' => 'SERVICE',
                        ],
                        2 => [
                            // 即将推出，敬请期待~
                            'type' => 'click',
                            'name' => '储蓄卡',
                            'key' => 'CARD'
                        ]
                    ]
                ]
            ]
        ];
    }
}
